當 歷史分歧 發生於儲存庫的時間軸分裂成多條非線性路徑時。這通常發生在功能分支(例如 news-hotfix)與主分支在共享共同祖先後各自獨立發展時。這種分叉導致快照的內部結構變得複雜。
1. 分叉觸發點
當開發者執行 git commit 於本地分支時,上游分支也接收了新的快照(例如對 index.html的更新)。這會產生一個 拓撲缺口 ,使你在 about/me.html 上的工作不再基於最新的專案狀態。
2. 非線性帶來的代價
雖然 Git 透過 遞歸合併來處理歷史分歧,但由此產生的歷史紀錄往往充滿「合併分支……」的提交。這使得 儲存庫歷史 難以審核,因為 git add 和 git commit 等檔案的操作順序 news-2.html 和 about/me.html 在視覺上變得交錯混亂。
3. 快照斷連
每次提交都會建立一個完整的 快照。當歷史出現分歧時,你的功能分支的 內部結構 缺乏其他位置同時變更的上下文,因此需要採用像重置(rebase)這樣的策略,以重新對齊專案的時間軸。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
What primary action triggers a divergent history in Git?
Deleting a branch locally.
Running git commit on a branch after the main branch has moved forward.
Staging files with git add without committing.
Checking out a new branch without making changes.
✅ Correct!
Divergence happens when both the feature branch and its parent branch receive new commits independently.❌ Incorrect
Divergence requires simultaneous evolution of two different branches.QUESTION 2
What is a negative consequence of 'braided' or non-linear history?
It corrupts the files in the working directory.
It prevents Git from tracking file changes.
It makes the repository history difficult to audit and follow logically.
It disables the use of the git status command.
✅ Correct!
Interleaved commits and frequent merge commits obscure the project's logical progression.❌ Incorrect
Git still tracks changes, but the 'log' becomes messy and harder for humans to read.QUESTION 3
Which file update in the example caused the 'upstream' branch to move ahead?
news-2.html
index.html
about/me.html
mary-bio.html
✅ Correct!
In the scenario, a colleague pushing changes to index.html created the upstream shift.❌ Incorrect
news-2.html and about/me.html were the local changes on the feature branch.QUESTION 4
When history diverges, what does the internal makeup of the feature branch lack?
The latest commit hashes from the local index.
The context of concurrent changes made in other branches.
The ability to run git status.
The connection to the initial root commit.
✅ Correct!
The feature branch 'forks' and is unaware of new snapshots created on the main branch.❌ Incorrect
Branches always share a root, but they lose a shared *current* baseline.QUESTION 5
Which Git command is most useful for visualizing a divergent history graph?
git commit -a
git log --oneline --graph
git add -u
git status
✅ Correct!
The --graph flag visually renders the branches and merge points in the terminal.❌ Incorrect
git status shows the working tree, not the historical graph.Case Study: The news-hotfix Divergence
Analyzing a repository split.
You are working on a 'news-hotfix' branch. You perform 'git add news-2.html' and 'git commit'. Simultaneously, your lead developer pushes a change to 'index.html' on the main branch. You then add 'about/me.html' and commit again.
Q
1. Explain why the news-hotfix branch is now considered 'diverged'.
Solution:
It is diverged because its lineage is missing the 'index.html' snapshot that now exists on the main branch tip. Both branches have a shared ancestor, but they have unique, conflicting tips.
It is diverged because its lineage is missing the 'index.html' snapshot that now exists on the main branch tip. Both branches have a shared ancestor, but they have unique, conflicting tips.
Q
2. What will the 'git log --oneline --graph' look like if you perform a standard merge now?
Solution:
It will show two parallel tracks that eventually rejoin at a 'Merge branch' commit, creating a 'bubble' or 'braided' look in the history.
It will show two parallel tracks that eventually rejoin at a 'Merge branch' commit, creating a 'bubble' or 'braided' look in the history.
Q
3. How does this divergence affect the 'internal makeup' of your snapshots?
Solution:
Your latest snapshots do not include the changes to 'index.html', meaning your local feature state is 'stale' relative to the most current version of the project.
Your latest snapshots do not include the changes to 'index.html', meaning your local feature state is 'stale' relative to the most current version of the project.